/**
 * Created by guillaume on 16/01/14.
 */
function notify(position, html, status, time) {
    var notif = $('<div class="notify"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + html + '</div>');
    notif.addClass('notify-' + status);
    var notifs = $('.notify');
    var offsetHeight = 0;

    notifs.each(function () {
        offsetHeight += $(this).outerHeight() + 10;
    });

    if (/^top-/.test(position))
        notif.css("top", (offsetHeight + 60) + "px");

    if (/^bottom-/.test(position))
        notif.css("bottom", (offsetHeight + 40) + "px");

    if (/^center-/.test(position))
        notif.css("top", Math.max(0, (($(window).height() - $(this).outerHeight()) / 2) + $(window).scrollTop()) + "px");

    if (/-right$/.test(position))
        notif.css("right", "15px");

    if (/-left$/.test(position))
        notif.css("left", "15px");

    if (/-center$/.test(position))
        notif.css("left", Math.max(0, (($(window).width() - $(this).outerWidth()) / 2) + $(window).scrollLeft()) + "px");
    notif.hide();

    $('#wrapper').append(notif);
    notif.slideDown(200).on('click', 'button.close', function(){
        notif.fadeOut('fast', function () {
            notif.remove();
        });
    });

    setTimeout(
        function () {
            notif.fadeOut('fast', function () {
                notif.remove();
            });
        },
        time
    );
}

$('#wrapper')